const ws = new Object({
    sessionId: `${guid()}`,
    stompClient: null,
    connect: (endpoint, callback) => {
        let socket = new SockJS(endpoint);
        ws.stompClient = Stomp.over(socket);
        ws.stompClient.connect({}, function (frame) {
            console.log('连接成功: ' + frame);

            if (callback) {
                callback();
            }
        });
    },

    subscribe: (subscribe, consumer) => {
        ws.stompClient.subscribe(subscribe, (msg) => consumer(JSON.parse(msg.body)));
    },

    sendMessage: (broker, msg) => {
        msg.sessionId = ws.sessionId;
        ws.stompClient.send(broker, {}, JSON.stringify(msg));
    },
    disconnect: function () {
        ws.stompClient.disconnect();
        console.log("Disconnected");
    },

});